﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace MS.INV.Reports.Profits
{
    public partial class Profit_Chart_Month : Lib.Bases.Forms.BaseForm
    {
        DataTable DT_C = new DataTable();

        public Profit_Chart_Month()
        {
            InitializeComponent();
            FDate.EditValue = DateTime.Now;
        }

        private void btRef_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                pivot.DataSource = DBLayer.ExecDataTable("Rpt_ProfitChartMonth", "Command,Month", "Detail", Convert.ToDateTime(FDate.EditValue));

                DT_C = DBLayer.ExecDataTable("Rpt_ProfitChartMonth", "Command,Month", "Summary", Convert.ToDateTime(FDate.EditValue));
                chart.Series[0].DataSource = DT_C;
                chart.Series[0].ArgumentDataMember = "Ngay";
                chart.Series[0].ValueScaleType = ScaleType.Numerical;
                chart.Series[0].ValueDataMembers.AddRange(new string[] { "LoiNhuan" });
                chart.Series[0].LegendText = "Lợi nhuận";//Convert.ToDateTime(FDate.EditValue).ToString("MM/yyyy");
                //chart.Series[0].PointOptions.ValueNumericOptions.

                chart.Series[1].DataSource = DT_C;
                chart.Series[1].ArgumentDataMember = "Ngay";
                chart.Series[1].ValueScaleType = ScaleType.Numerical;
                chart.Series[1].ValueDataMembers.AddRange(new string[] { "DoanhThu" });
                chart.Series[1].LegendText = "Doanh thu";
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Load data");
            }
        }

        private void btExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (Exports.Profits.Profit_Chart_Month cls = new Exports.Profits.Profit_Chart_Month())
            {
                cls.DoExport(DT_C, Convert.ToDateTime(FDate.EditValue));
            }
            if (System.IO.File.Exists(Application.StartupPath + @"\Export Xls\Profit_Chart_Month.xls"))
                Lib.Utils.Uti.RunFile(Application.StartupPath + @"\Export Xls\Profit_Chart_Month.xls");
        }

        private void btClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}
